package com.example.gridviewexample;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class GridViewAdapter extends BaseAdapter {
	
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;
	
	private Activity activity;

	public GridViewAdapter(Activity a, ArrayList<HashMap<String, String>> data) {
		this.activity = a;
		this.data = data;
		
		inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if (convertView == null) {
			vi = inflater.inflate(R.layout.gridview_row, null);
		}
		
		TextView title = (TextView) vi.findViewById(R.id.textView1);

		HashMap<String, String> item = new HashMap<String, String>();
		item = data.get(position);
		
		System.out.println("title: " + item.get("title"));
		title.setText(item.get("title"));
		

		return vi;
	}

}
